package com.hitcoder.chat.emoji

import android.text.TextUtils
import com.hitcoder.chat.R
import java.util.*

/**
 * 编码参考 http://www.oicqzone.com/tool/emoji/
 */
object Emotions {
    var EMOTIONS: MutableMap<String, Int> = LinkedHashMap()
    val emotions: List<Emotion>
        get() {
            val emotions: MutableList<Emotion> = ArrayList()
            for ((key, value) in EMOTIONS) {
                emotions.add(Emotion(key, value))
            }
            return emotions
        }

    init {
        EMOTIONS[emotionCode2String(128516)] = R.mipmap.emoji_0x1f604
        EMOTIONS[emotionCode2String(128515)] = R.mipmap.emoji_0x1f603
        EMOTIONS[emotionCode2String(128522)] = R.mipmap.emoji_0x1f60a
        EMOTIONS[emotionCode2String(128521)] = R.mipmap.emoji_0x1f609
        EMOTIONS[emotionCode2String(128525)] = R.mipmap.emoji_0x1f60d
        EMOTIONS[emotionCode2String(128536)] = R.mipmap.emoji_0x1f618
        EMOTIONS[emotionCode2String(128538)] = R.mipmap.emoji_0x1f61a
        EMOTIONS[emotionCode2String(128540)] = R.mipmap.emoji_0x1f61c
        EMOTIONS[emotionCode2String(128541)] = R.mipmap.emoji_0x1f61d
        EMOTIONS[emotionCode2String(128563)] = R.mipmap.emoji_0x1f633
        EMOTIONS[emotionCode2String(128513)] = R.mipmap.emoji_0x1f601
        EMOTIONS[emotionCode2String(128532)] = R.mipmap.emoji_0x1f614
        EMOTIONS[emotionCode2String(128524)] = R.mipmap.emoji_0x1f60c
        EMOTIONS[emotionCode2String(128530)] = R.mipmap.emoji_0x1f612
        EMOTIONS[emotionCode2String(128542)] = R.mipmap.emoji_0x1f61e
        EMOTIONS[emotionCode2String(128547)] = R.mipmap.emoji_0x1f623
        EMOTIONS[emotionCode2String(128546)] = R.mipmap.emoji_0x1f622
        EMOTIONS[emotionCode2String(128514)] = R.mipmap.emoji_0x1f602
        EMOTIONS[emotionCode2String(128557)] = R.mipmap.emoji_0x1f62d
        EMOTIONS[emotionCode2String(128554)] = R.mipmap.emoji_0x1f62a
        EMOTIONS[emotionCode2String(128549)] = R.mipmap.emoji_0x1f625
        EMOTIONS[emotionCode2String(128560)] = R.mipmap.emoji_0x1f630
        EMOTIONS[emotionCode2String(128531)] = R.mipmap.emoji_0x1f613
        EMOTIONS[emotionCode2String(128552)] = R.mipmap.emoji_0x1f628
        EMOTIONS[emotionCode2String(128561)] = R.mipmap.emoji_0x1f631
        EMOTIONS[emotionCode2String(128544)] = R.mipmap.emoji_0x1f620
        EMOTIONS[emotionCode2String(128545)] = R.mipmap.emoji_0x1f621
        EMOTIONS[emotionCode2String(128534)] = R.mipmap.emoji_0x1f616
        EMOTIONS[emotionCode2String(128567)] = R.mipmap.emoji_0x1f637
        EMOTIONS[emotionCode2String(128562)] = R.mipmap.emoji_0x1f632
        EMOTIONS[emotionCode2String(128127)] = R.mipmap.emoji_0x1f47f
        EMOTIONS[emotionCode2String(128527)] = R.mipmap.emoji_0x1f60f
        EMOTIONS[emotionCode2String(128102)] = R.mipmap.emoji_0x1f466
        EMOTIONS[emotionCode2String(128103)] = R.mipmap.emoji_0x1f467
        EMOTIONS[emotionCode2String(128104)] = R.mipmap.emoji_0x1f468
        EMOTIONS[emotionCode2String(128105)] = R.mipmap.emoji_0x1f469
        EMOTIONS[emotionCode2String(127775)] = R.mipmap.emoji_0x1f31f
        EMOTIONS[emotionCode2String(128068)] = R.mipmap.emoji_0x1f444
        EMOTIONS[emotionCode2String(128077)] = R.mipmap.emoji_0x1f44d
        EMOTIONS[emotionCode2String(128078)] = R.mipmap.emoji_0x1f44e
        EMOTIONS[emotionCode2String(128076)] = R.mipmap.emoji_0x1f44c
        EMOTIONS[emotionCode2String(128074)] = R.mipmap.emoji_0x1f44a
        EMOTIONS[fromChar('✊')] = R.mipmap.emoji_0x270a
        EMOTIONS[fromChar('✌')] = R.mipmap.emoji_0x270c
        EMOTIONS[emotionCode2String(128070)] = R.mipmap.emoji_0x1f446
        EMOTIONS[emotionCode2String(128071)] = R.mipmap.emoji_0x1f447
        EMOTIONS[emotionCode2String(128073)] = R.mipmap.emoji_0x1f449
        EMOTIONS[emotionCode2String(128072)] = R.mipmap.emoji_0x1f448
        EMOTIONS[emotionCode2String(128591)] = R.mipmap.emoji_0x1f64f
        EMOTIONS[emotionCode2String(128079)] = R.mipmap.emoji_0x1f44f
        EMOTIONS[emotionCode2String(128170)] = R.mipmap.emoji_0x1f4aa
        EMOTIONS[emotionCode2String(128087)] = R.mipmap.emoji_0x1f457
        EMOTIONS[emotionCode2String(127872)] = R.mipmap.emoji_0x1f380
        EMOTIONS[fromChar('❤')] = R.mipmap.emoji_0x2764
        EMOTIONS[emotionCode2String(128148)] = R.mipmap.emoji_0x1f494
        EMOTIONS[emotionCode2String(128142)] = R.mipmap.emoji_0x1f48e
        EMOTIONS[emotionCode2String(128054)] = R.mipmap.emoji_0x1f436
        EMOTIONS[emotionCode2String(128049)] = R.mipmap.emoji_0x1f431
        EMOTIONS[emotionCode2String(127801)] = R.mipmap.emoji_0x1f339
        EMOTIONS[emotionCode2String(127803)] = R.mipmap.emoji_0x1f33b
        EMOTIONS[emotionCode2String(127809)] = R.mipmap.emoji_0x1f341
        EMOTIONS[emotionCode2String(127811)] = R.mipmap.emoji_0x1f343
        EMOTIONS[emotionCode2String(127769)] = R.mipmap.emoji_0x1f319
        EMOTIONS[fromChar('☀')] = R.mipmap.emoji_0x2600
        EMOTIONS[fromChar('☁')] = R.mipmap.emoji_0x2601
        EMOTIONS[fromChar('⚡')] = R.mipmap.emoji_0x26a1
        EMOTIONS[fromChar('☔')] = R.mipmap.emoji_0x2614
        EMOTIONS[emotionCode2String(128123)] = R.mipmap.emoji_0x1f47b
        EMOTIONS[emotionCode2String(127877)] = R.mipmap.emoji_0x1f385
        EMOTIONS[emotionCode2String(127873)] = R.mipmap.emoji_0x1f381
        EMOTIONS[emotionCode2String(128241)] = R.mipmap.emoji_0x1f4f1
        EMOTIONS[emotionCode2String(128269)] = R.mipmap.emoji_0x1f50d
        EMOTIONS[emotionCode2String(128163)] = R.mipmap.emoji_0x1f4a3
        EMOTIONS[fromChar('⚽')] = R.mipmap.emoji_0x26bd
        EMOTIONS[fromChar('☕')] = R.mipmap.emoji_0x2615
        EMOTIONS[emotionCode2String(127866)] = R.mipmap.emoji_0x1f37a
        EMOTIONS[emotionCode2String(127874)] = R.mipmap.emoji_0x1f382
        EMOTIONS[emotionCode2String(127968)] = R.mipmap.emoji_0x1f3e0
        EMOTIONS[emotionCode2String(128663)] = R.mipmap.emoji_0x1f697
    }

    private fun emotionCode2String(code: Int): String {
        return if (Character.charCount(code) == 1) {
            code.toString()
        } else {
            String(Character.toChars(code))
        }
    }

    private fun fromChar(ch: Char): String {
        return ch.toString()
    }

    @JvmStatic
    fun getDrawableResByName(emotionName: String): Int {
        if (!TextUtils.isEmpty(emotionName) && EMOTIONS.containsKey(emotionName)) {
            val integer = EMOTIONS[emotionName]
            return integer ?: -1
        }
        return -1
    }


}